package main

import (
	"encoding/json"
	"fmt"
)

/*以下为推送相关*/

func postStorm(roomid, gid, start, time, online, uid, uname, face, official_type, official_desc interface{}) {
	type a struct {
		RoomId       interface{} `json:"room_id"`
		RaffleId     interface{} `json:"raffle_id"`
		RaffleType   interface{} `json:"raffle_type"`
		StartTime    interface{} `json:"start_time"`
		Time         interface{} `json:"time"`
		Online       interface{} `json:"online"`
		UID          interface{} `json:"uid"`
		Uname        interface{} `json:"uname"`
		Face         interface{} `json:"face"`
		OfficialType interface{} `json:"official_type"`
		OfficialDesc interface{} `json:"official_desc"`
	}
	aa := a{roomid, gid, "STORM", start, time, online, uid, uname, face, official_type, official_desc}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
}
func postAnchor(roomid, gid int, AwardName string, RequireType, RequireValue, GiftPrice int, start, time, online int, uid, uname, face, official_type, official_desc, awardNum, awardType interface{}) {
	type a struct {
		RoomId       int         `json:"room_id"`
		RaffleId     int         `json:"raffle_id"`
		RaffleType   string      `json:"raffle_type"`
		AwardName    string      `json:"award_name"`
		RequireType  int         `json:"require_type"`
		RequireValue int         `json:"require_value"`
		GiftPrice    int         `json:"gift_price"`
		StartTime    int         `json:"start_time"`
		Time         int         `json:"time"`
		Online       interface{} `json:"online"`
		UID          interface{} `json:"uid"`
		Uname        interface{} `json:"uname"`
		Face         interface{} `json:"face"`
		OfficialType interface{} `json:"official_type"`
		OfficialDesc interface{} `json:"official_desc"`
		AwardNum     interface{} `json:"award_num"`
		AwardType    interface{} `json:"award_type"`
	}
	aa := a{roomid, gid, "ANCHOR", AwardName, RequireType, RequireValue, GiftPrice, start, time, online, uid, uname, face, official_type, official_desc, awardNum, awardType}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
}
func postRed(roomid, gid, start, time, online interface{}, uid, uname, face, official_type, official_desc interface{}) {
	type a struct {
		RoomId       interface{} `json:"room_id"`
		RaffleId     interface{} `json:"raffle_id"`
		RaffleType   interface{} `json:"raffle_type"`
		StartTime    interface{} `json:"start_time"`
		Time         interface{} `json:"time"`
		Online       interface{} `json:"online"`
		UID          interface{} `json:"uid"`
		Uname        interface{} `json:"uname"`
		Face         interface{} `json:"face"`
		OfficialType interface{} `json:"official_type"`
		OfficialDesc interface{} `json:"official_desc"`
	}
	aa := a{roomid, gid, "RED", start, time, online, uid, uname, face, official_type, official_desc}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
}

func postPopRed(roomid, gid, totalprice, start, time, online interface{}, uid, uname, face, official_type, official_desc, rp_type interface{}) {
	type a struct {
		RoomId       interface{} `json:"room_id"`
		RaffleId     interface{} `json:"raffle_id"`
		RaffleType   interface{} `json:"raffle_type"`
		TotalPrice   interface{} `json:"total_price"`
		StartTime    interface{} `json:"start_time"`
		Time         interface{} `json:"time"`
		Online       interface{} `json:"online"`
		UID          interface{} `json:"uid"`
		Uname        interface{} `json:"uname"`
		Face         interface{} `json:"face"`
		OfficialType interface{} `json:"official_type"`
		OfficialDesc interface{} `json:"official_desc"`
		Rp_type      interface{} `json:"rp_type"`
	}
	aa := a{roomid, gid, "POPULARITY_RED", totalprice, start, time, online, uid, uname, face, official_type, official_desc, rp_type}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
}

func postOnline(roomid, online interface{}) {
	type a struct {
		RoomId interface{} `json:"room_id"`
		Online interface{} `json:"online"`
	}
	type a0 struct {
		Refresh a `json:"refresh"`
	}
	aa := a{roomid, online}
	aa0 := a0{aa}
	b, err := json.Marshal(aa0)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
	//fmt.Println(TI(), roomid, online)
}
func postAttended(raffle_id, attended interface{}) {
	type a struct {
		RaffleId interface{} `json:"raffle_id"`
		Attended interface{} `json:"attended"`
	}
	type a0 struct {
		Refresh a `json:"refresh"`
	}
	aa := a{raffle_id, attended}
	aa0 := a0{aa}
	b, err := json.Marshal(aa0)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
	//fmt.Println(TI(), "参与", raffle_id, attended)
}

func postMonitorErr(err, now interface{}) {
	type a struct {
		Err interface{} `json:"err"`
		Now interface{} `json:"now"`
	}
	aa := a{err, now}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
	//fmt.Println(TI(), "参与", raffle_id, attended)
}
func postMonitorRooms() {
	runs, notRuns := []int{}, []int{}
	bDlock.RLock()
	for k, v := range bDmap {
		if v.roomid != 0 {
			runs = append(runs, k)
		} else {
			notRuns = append(notRuns, k)
		}
	}
	bDlock.RUnlock()

	type a struct {
		Runs    interface{} `json:"runs"`
		NotRuns interface{} `json:"not_runs"`
	}
	aa := a{runs, notRuns}
	b, err := json.Marshal(aa)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
	//fmt.Println(TI(), string(b))
}

func postRoomGift(roomid, uname, gift, num, batch_combo_id interface{}) {
	type a struct {
		RoomId         interface{} `json:"room_id"`
		Uname          interface{} `json:"uname"`
		Gift           interface{} `json:"gift_name"`
		Num            interface{} `json:"gift_num"`
		Batch_combo_id interface{} `json:"batch_combo_id"`
	}
	type a0 struct {
		Refresh a `json:"RoomGift"`
	}
	aa := a{roomid, uname, gift, num, batch_combo_id}
	aa0 := a0{aa}
	b, err := json.Marshal(aa0)
	if err != nil {
		fmt.Println("error:", err)
	}
	post(string(b))
	//fmt.Println(TI(), roomid, online)
}
func post(data string) {
	//fmt.Println(other.TI() + data)
	send2server(data)
}
